<?php
class UserIdentity extends CUserIdentity{
	public $_id = "";
	public function authenticate(){
		$member = Member::model()->findByAttributes(array(
					'email' => $this->username
				));
		if (!is_object($member)) {
			$this->errorCode=self::ERROR_USERNAME_INVALID;
			$this->errorMessage = "Email không đúng hoặc không tồn tại";
		} else if ($member->password !== hashStr($this->password,2) ) {
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
			$this->errorMessage = "Mật khẩu không đúng";
		} else {
			$this->errorCode = self::ERROR_NONE;
			$this->_id = $member->_id.'';
			$this->setState('roles', $member->type_member);
			$this->setState('title', $member->type_member);
			$this->setState('_id', $member->_id.'');
			$this->setState('_current', $member);
			return true;
		}
	}

	public function getId(){
		return $this->_id;
	}
}